package com.tbit.main.service.impl;

import com.tbit.main.constant.AccountDayStatConstant;
import com.tbit.main.constant.DaoParamConstant;
import com.tbit.main.dao.stat.AccountDayStatDao;
import com.tbit.main.dao.stat.VipCardOrderDayStaDao;
import com.tbit.main.pojo.AccountDayStat;
import com.tbit.main.pojo.VipCardOrderDaySta;
import com.tbit.main.service.VipCardOrderDayStaService;
import com.tbit.main.util.DateTimeUtil;
import com.tbit.main.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author LMY
 * @create 2021-01-11 20:26
 * 会员卡订单日统计
 */
@Service("vipCardOrderDayStaService")
public class VipCardOrderDayStaServiceImpl implements VipCardOrderDayStaService {

    @Autowired
    private VipCardOrderDayStaDao vipCardOrderDayStaDao;
    @Autowired
    private AccountDayStatDao accountDayStatDao;

    @Override
    public List<VipCardOrderDaySta> getByAccountIdDateDay(List<Integer> accountIds, String startDate, String endDate) {
        Map<String, Object> map = new HashMap<>();
        map.put(DaoParamConstant.accountId, StringUtil.getListString(accountIds));
        map.put("startDate", DateTimeUtil.getYYMMDDInteger(startDate));
        map.put("endDate", DateTimeUtil.getYYMMDDInteger(endDate));
        map.put("dataType", AccountDayStatConstant.MEMBERSHIP_CARD_INCOME);
        //return vipCardOrderDayStaDao.getByAccountIdDateDay(map);
        List<AccountDayStat> accountDayStats = accountDayStatDao.getByAccountIdDateDay(map);
        List<VipCardOrderDaySta> vipCardOrderDayStaList = accountDayStats.stream().map(l -> new VipCardOrderDaySta(l.getAccountId(), l.getCntTotal(), l.getSumTotal(), DateTimeUtil.getYY_MM_DD(l.getDataDate().toString()), l.getAddTime(), l.getDateWeek(), l.getDateMonth())).collect(Collectors.toList());
        return vipCardOrderDayStaList;
    }

    @Override
    public List<VipCardOrderDaySta> getByAccountIdDateWeek(List<Integer> accountIds, String startDate, String endDate) {
        Map<String, Object> map = new HashMap<>();
        map.put(DaoParamConstant.accountId, StringUtil.getListString(accountIds));
        map.put("startDate", DateTimeUtil.getYYMMDDInteger(startDate));
        map.put("endDate", DateTimeUtil.getYYMMDDInteger(endDate));
        map.put("dataType", AccountDayStatConstant.MEMBERSHIP_CARD_INCOME);
        //return vipCardOrderDayStaDao.getByAccountIdDateWeek(map);
        List<AccountDayStat> accountDayStats = accountDayStatDao.getByAccountIdDateWeek(map);
        List<VipCardOrderDaySta> vipCardOrderDayStaList = accountDayStats.stream().map(l -> new VipCardOrderDaySta(l.getAccountId(), l.getCntTotal(), l.getSumTotal(), DateTimeUtil.getYY_MM_DD(l.getDataDate().toString()), l.getAddTime(), l.getDateWeek(), l.getDateMonth())).collect(Collectors.toList());
        return vipCardOrderDayStaList;
    }

    @Override
    public List<VipCardOrderDaySta> getByAccountIdDateMonth(List<Integer> accountIds, String startDate, String endDate) {
        Map<String, Object> map = new HashMap<>();
        map.put(DaoParamConstant.accountId, StringUtil.getListString(accountIds));
        map.put("startDate", DateTimeUtil.getYYMMDDInteger(startDate));
        map.put("endDate", DateTimeUtil.getYYMMDDInteger(endDate));
        map.put("dataType", AccountDayStatConstant.MEMBERSHIP_CARD_INCOME);
        //return vipCardOrderDayStaDao.getByAccountIdDateMonth(map);
        List<AccountDayStat> accountDayStats = accountDayStatDao.getByAccountIdDateMonth(map);
        List<VipCardOrderDaySta> vipCardOrderDayStaList = accountDayStats.stream().map(l -> new VipCardOrderDaySta(l.getAccountId(), l.getCntTotal(), l.getSumTotal(), DateTimeUtil.getYY_MM_DD(l.getDataDate().toString()), l.getAddTime(), l.getDateWeek(), l.getDateMonth())).collect(Collectors.toList());
        return vipCardOrderDayStaList;
    }

    @Override
    public Map<String, Object> getByAccountIds(List<Integer> accountIds, String startDate, String endDate) {
        Map<String, Object> map = new HashMap<>();
        map.put(DaoParamConstant.accountId, StringUtil.getListString(accountIds));
        map.put("startDate", startDate);
        map.put("endDate", endDate);
        return vipCardOrderDayStaDao.getByAccountIds(map);
    }

    @Override
    public Map<String, Object> getByAccountId(Integer accountId, String startDate, String endDate) {
        Map<String, Object> map = new HashMap<>();
        map.put(DaoParamConstant.accountId, accountId);
        map.put("startDate", startDate);
        map.put("endDate", endDate);
        return vipCardOrderDayStaDao.getByAccountId(map);
    }
}
